﻿/*
Copyright (c) 2012 Maksim Gordeev

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

 */


/*
 * Сделано в SharpDevelop.
 * Пользователь: max
 * Дата: 12.05.2012
 * Время: 15:45
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using Newtonsoft.Json;
using System.IO;
using System.ComponentModel;
using System.Windows.Media.Imaging;

namespace jellybird.core
{
	/*
	 * https://dev.twitter.com/docs/platform-objects/users
	 * 
	 */
	
	/// <summary>
	/// Twitter User
	/// </summary>
	[TypeConverter(typeof(ExpandableObjectConverter))]
	[JsonObject(MemberSerialization.OptIn)]
	public class TwUser:TwObjectBase
	{
		public TwUser()
		{
		}
		
		/*
		 * https://dev.twitter.com/discussions/9568
		 * About profile images
		 */
		
		#region profile images
		[JsonIgnore()]
		public BitmapImage ProfileImageMini
		{
			get
			{
				return TwImageProfileCache.GetImageCacheMini().GetProfileImage(this);
			}
		}
		
		[JsonIgnore()]
		public BitmapImage ProfileImageNormal
		{
			get
			{ 
				return TwImageProfileCache.GetImageCacheNormal().GetProfileImage(this);
			}
		}
		
		[JsonIgnore()]
		public BitmapImage ProfileImageBigger
		{
			get 
			{
				return TwImageProfileCache.GetImageCacheBigger().GetProfileImage(this);
			}
		}
		
		#endregion
		
		#region TwUser props
		//на самом деле атрибут не нужен
		//json сериализатор по умолчанию обрабатывает только public свойства
		[JsonIgnore()]
		bool contributorsEnabled=false;
		
		/// <summary>
		/// Indicates that the user has an account
		///	with "contributor mode" enabled, allowing
		///	for Tweets issued by the user to be co-authored by another account.
		/// </summary>
		/// <example>
		/// "contributors_enabled": false
		/// </example>
		[JsonProperty("contributors_enabled")]
		public bool ContributorsEnabled
		{
			get { return contributorsEnabled; }
			set { contributorsEnabled = value; }
		}
		
		[JsonIgnore()]
		string createdAt=string.Empty;

		/// <summary>
		/// The UTC datetime that the user account was created on Twitter
		/// "created_at": "Mon Nov 29 21:18:15 +0000 2010"
		/// </summary>
		/// <example>
		/// "contributors_enabled": false
		/// </example>
		[JsonProperty("created_at")]
		public string CreatedAtStr
		{
			get { return createdAt; }
			set
			{
				if(Helper.TryParseFromTw(value,ref createdAtDateTime))
					createdAt = value;
				else
					throw new FormatException(string.Format("Cannot parse time string '{0}'",value));
			}
		}
		
		
		
		DateTime createdAtDateTime=DateTime.MinValue;
		
		[JsonIgnore()]
		public DateTime CreatedAt
		{
			get
			{
				return createdAtDateTime;
			}
			set
			{
				createdAtDateTime=value;
				// и в строку:
				createdAt=Helper.TwTimeFromDatetime(value);
			}
		}
		
		[JsonIgnore()]
		bool defaultprofile=false;
		
		/// <summary>
		/// When true, indicates that the user
		///	has not altered the theme or background of their user profile.
		/// </summary>
		/// <example>
		/// "default_profile": false
		/// </example>
		[JsonProperty("default_profile")]
		public bool Defaultprofile {
			get { return defaultprofile; }
			set { defaultprofile = value; }
		}
		
		[JsonIgnore()]
		bool defaultProfileImage=false;
		
		/// <summary>
		/// When true, indicates that the user has not uploaded their
		///	own avatar and a default egg avatar is used instead.
		/// </summary>
		/// <example>
		/// "default_profile_image": false
		/// </example>
		[JsonProperty("default_profile_image")]
		public bool DefaultProfileImage {
			get { return defaultProfileImage; }
			set { defaultProfileImage = value; }
		}
		
		[JsonIgnore()]
		string description=null;
		
		/// <summary>
		/// Nullable. The user-defined UTF-8 string describing their account.
		/// </summary>
		/// <example>
		/// "description":"The Real Twitter API."
		/// </example>
		[JsonProperty("description")]
		public string Description {
			get { return description; }
			set { description = value; }
		}
		
		[JsonIgnore()]
		int favouritesCount=0;
		
		/// <summary>
		/// The number of tweets this user has favorited
		///	in the account's lifetime. British spelling
		///	used in the field name for historical reasons
		/// </summary>
		/// <example>
		/// "favourites_count": 13
		/// </example>
		[JsonProperty("favourites_count")]
		public int FavouritesCount {
			get { return favouritesCount; }
			set { favouritesCount = value; }
		}
		
		[JsonIgnore()]
		bool? followRequestSent=null;
		/// <summary>
		/// Nullable. Perspectival. When true, indicates that
		///	the authenticating user has issued a follow request
		///	to this protected user account
		/// </summary>
		/// <example>
		/// "follow_request_sent":false
		/// </example>
		[JsonProperty("follow_request_sent")]
		public bool? FollowRequestSent {
			get { return followRequestSent; }
			set { followRequestSent = value; }
		}
		
		[JsonIgnore()]
		bool? following=null;
		
		/*
		 * see:
		 * http://groups.google.com/group/twitter-development-talk/browse_thread/thread/42ba883b9f8e3c6e?tvc=2&pli=1
		 */
		/// <summary>
		/// Nullable. Perspectival. Deprecated. When true, indicates that
		///	the authenticating user is following this user. Some false negatives
		///	are possible when set to "false", but these false negatives are
		///	increasingly being represented as "null" instead
		/// </summary>
		/// <example>
		/// "following": true
		/// </example>
		[JsonProperty("following")]
		public bool? Following {
			get { return following; }
			set { following = value; }
		}
		
		[JsonIgnore()]
		int followersCount=0;
		
		/// <summary>
		/// The number of followers this account currently has. Under certain
		///	conditions of duress, this field will temporarily indicate "0."
		/// </summary>
		/// <example>
		/// "followers_count": 21
		/// </example>
		[JsonProperty("followers_count")]
		public int FollowersCount {
			get { return followersCount; }
			set { followersCount = value; }
		}
		
		[JsonIgnore()]
		int friendCount=0;
		
		/// <summary>
		/// The number of users this account is following (AKA their "followings").
		///	Under certain conditions of duress, this field will temporarily indicate "0."
		/// </summary>
		/// <example>
		/// "friends_count": 32
		/// </example>
		[JsonProperty("friends_count")]
		public int FriendsCount {
			get { return friendCount; }
			set { friendCount = value; }
		}
		
		[JsonIgnore()]
		bool geoEnabled=false;
		
		/// <summary>
		/// When true, indicates that the user has enabled the possibility
		///	of geotagging their Tweets. This field must be true for the current
		///	user to attach geographic data when using POST statuses/update.
		/// </summary>
		/// <example>
		/// "geo_enabled": true
		/// </example>
		[JsonProperty("geo_enabled")]
		public bool GeoEnabled {
			get { return geoEnabled; }
			set { geoEnabled = value; }
		}
		
		[JsonIgnore()]
		long id=0L;
		
		/// <summary>
		/// The integer representation of the unique identifier for this User.
		///	This number is greater than 53 bits and some programming languages
		///	may have difficulty/silent defects in interpreting it. Using a signed
		///	64 bit integer for storing this identifier is safe. Use id_str
		///	for fetching the identifier to stay on the safe side.
		///	See <see cref="https://dev.twitter.com/docs/twitter-ids-json-and-snowflake">Twitter IDs, JSON and Snowflake</see>.
		/// </summary>
		/// <example>
		/// "id":6253282
		/// </example>
		[JsonProperty("id")]
		public long Id {
			get { return id; }
			set { id = value; }
		}
		
		[JsonIgnore()]
		string idString="0";
		
		/// <summary>
		/// The string representation of the unique identifier for this Tweet.
		///	Implementations should use this rather than the large integer in id.
		/// </summary>
		/// <example>
		/// "id_str":"6253282"
		/// </example>
		[JsonProperty("id_str")]
		public string IdString {
			get { return idString; }
			set { idString = value; }
		}
		
		[JsonIgnore()]
		bool isTranslator=false;
		
		/// <summary>
		/// When true, indicates that the user is a participant in Twitter's
		///	translator community.
		/// </summary>
		/// <example>
		/// "is_translator": false
		/// </example>
		[JsonProperty("is_translator")]
		public bool IsTranslator {
			get { return isTranslator; }
			set { isTranslator = value; }
		}
		
		[JsonIgnore()]
		string lang=string.Empty;
		
		/// <summary>
		/// The ISO 639-1 two-letter character code for the user's
		///	self-declared user interface language. May or may not have
		///	anything to do with the content of their Tweets.
		/// </summary>
		/// <example>
		/// "lang": "en"
		/// </example>
		[JsonProperty("lang")]
		public string Lang {
			get { return lang; }
			set { lang = value; }
		}
		
		[JsonIgnore()]
		int listedCount=0;
		
		/// <summary>
		/// The number of public lists that this user is a member of.
		/// </summary>
		/// <example>
		/// "listed_count":9274
		/// </example>
		[JsonProperty("listed_count")]
		public int ListedCount {
			get { return listedCount; }
			set { listedCount = value; }
		}
		
		[JsonIgnore()]
		string location=null;
		
		/// <summary>
		/// Nullable. The user-defined location for this account's profile.
		///	Not necessarily a location nor parseable. This field
		///	will occasionally be fuzzily interpreted by the Search service.
		/// </summary>
		/// <example>
		/// "location":"San Francisco, CA"
		/// </example>
		[JsonProperty("location")]
		public string Location {
			get { return location; }
			set { location = value; }
		}
		
		[JsonIgnore()]
		string userName=string.Empty;
		
		/// <summary>
		///	The name of the user, as they've defined it. Not necessarily
		///	a person's name. Typically capped at 20 characters, but subject to change.
		/// </summary>
		/// <example>
		/// "name":"Twitter API"
		/// </example>
		[JsonProperty("name")]
		public string UserName {
			get { return userName; }
			set { userName = value; }
		}
		
		[JsonIgnore()]
		bool? notificationsEnable;
		
		/// <summary>
		///	Nullable. Deprecated. May incorrectly report "false" at times.
		///	Indicates whether the authenticated user has chosen to receive
		///	this user's tweets by SMS.
		/// </summary>
		[JsonProperty("notifications")]
		public bool? NotificationsEnable {
			get { return notificationsEnable; }
			set { notificationsEnable = value; }
		}
		
		[JsonIgnore()]
		string profileBackgroundColor=string.Empty;
		
		/// <summary>
		/// The hexadecimal color chosen by the user for their background.
		/// </summary>
		/// <example>
		/// "profile_background_color":"e8f2f7"
		/// </example>
		[JsonProperty("profile_background_color")]
		public string ProfileBackgroundColor {
			get { return profileBackgroundColor; }
			set { profileBackgroundColor = value; }
		}
		
		[JsonIgnore()]
		string profileBackgroundImageUrl=string.Empty;
		
		/// <summary>
		/// A HTTP-based URL pointing to the background image the user
		///	has uploaded for their profile.
		/// </summary>
		/// <example>
		/// "profile_background_image_url":"http:\/\/a2.twimg.com\/profile_background_images\/229557229\/twitterapi-bg.png"
		/// </example>
		[JsonProperty("profile_background_image_url")]
		public string ProfileBackgroundImageUrl {
			get { return profileBackgroundImageUrl; }
			set { profileBackgroundImageUrl = value; }
		}
		
		[JsonIgnore()]
		string profileBackgroundImgeUrlHttps=string.Empty;
		
		/// <summary>
		/// A HTTPS-based URL pointing to the background image the user
		///	has uploaded for their profile.
		/// </summary>
		/// <example>
		/// "profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/229557229\/twitterapi-bg.png"
		/// </example>
		[JsonProperty("profile_background_image_url_https")]
		public string ProfileBackgroundImgeUrlHttps {
			get { return profileBackgroundImgeUrlHttps; }
			set { profileBackgroundImgeUrlHttps = value; }
		}
		
		[JsonIgnore()]
		bool profileBackgroundImageTile=false;
		
		/// <summary>
		/// When true, indicates that the user's profile_background_image_url
		///	should be tiled when displayed
		/// </summary>
		/// <example>
		/// "profile_background_tile":false
		/// </example>
		[JsonProperty("profile_background_tile")]
		public bool ProfileBackgroundImageTile {
			get { return profileBackgroundImageTile; }
			set { profileBackgroundImageTile = value; }
		}
		
		[JsonIgnore()]
		string profileImageUrl=string.Empty;
		
		/// <summary>
		/// A HTTP-based URL pointing to the user's avatar image
		/// </summary>
		/// <example>
		/// "profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1438634086\/avatar_normal.png"
		/// </example>
		[JsonProperty("profile_image_url")]
		public string ProfileImageUrl {
			get { return profileImageUrl; }
			set { profileImageUrl = value; }
		}
		
		[JsonIgnore()]
		string profileImageUrlHttps=string.Empty;
		
		/// <summary>
		/// A HTTPS-based URL pointing to the user's avatar image.
		/// </summary>
		/// <example>
		/// "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1438634086\/avatar_normal.png"
		/// </example>
		[JsonProperty("profile_image_url_https")]
		public string ProfileImageUrlHttps {
			get { return profileImageUrlHttps; }
			set { profileImageUrlHttps = value; }
		}
		
		[JsonIgnore()]
		string profileLinkColor=string.Empty;
		
		/// <summary>
		/// The hexadecimal color the user has chosen to display links with in their Twitter UI.
		/// </summary>
		/// <example>
		/// "profile_link_color":"0094C2"
		/// </example>
		[JsonProperty("profile_link_color")]
		public string ProfileLinkColor {
			get { return profileLinkColor; }
			set { profileLinkColor = value; }
		}
		
		[JsonIgnore()]
		string profileSidebarBorderColor=string.Empty;
		
		/// <summary>
		///	The hexadecimal color the user has chosen to display
		///	sidebar borders with in their Twitter UI.
		/// </summary>
		/// <example>
		/// "profile_sidebar_border_color":"0094C2"
		/// </example>
		[JsonProperty("profile_sidebar_border_color")]
		public string ProfileSidebarBorderColor {
			get { return profileSidebarBorderColor; }
			set { profileSidebarBorderColor = value; }
		}
		
		[JsonIgnore()]
		string profileSidebarFillColor;
		
		/// <summary>
		/// The hexadecimal color the user has chosen to display sidebar
		///	backgrounds with in their Twitter UI.
		/// </summary>
		/// <example>
		/// "profile_sidebar_fill_color":"a9d9f1"
		/// </example>
		[JsonProperty("profile_sidebar_fill_color")]
		public string ProfileSidebarFillColor {
			get { return profileSidebarFillColor; }
			set { profileSidebarFillColor = value; }
		}
		
		[JsonIgnore()]
		string profileTextColor=string.Empty;
		
		/// <summary>
		/// The hexadecimal color the user has chosen to display text with in their Twitter UI.
		/// </summary>
		/// <example>
		/// "profile_text_color":"437792"
		/// </example>
		[JsonProperty("profile_text_color")]
		public string ProfileTextColor {
			get { return profileTextColor; }
			set { profileTextColor = value; }
		}
		
		[JsonIgnore()]
		bool profileUseBackgroundImage=false;
		
		/// <summary>
		/// When true, indicates the user wants their uploaded background image to be used.
		/// </summary>
		/// <example>
		/// "profile_use_background_image":true
		/// </example>
		[JsonProperty("profile_use_background_image")]
		public bool ProfileUseBackgroundImage {
			get { return profileUseBackgroundImage; }
			set { profileUseBackgroundImage = value; }
		}
		
		[JsonIgnore()]
		bool userProtected=false;
		
		/// <summary>
		/// When true, indicates that this user has chosen to protect their Tweets.
		/// </summary>
		/// <example>
		/// "protected": true
		/// </example>
		[JsonProperty("protected")]
		public bool UserProtected {
			get { return userProtected; }
			set { userProtected = value; }
		}
		
		[JsonIgnore()]
		string screenName=null;
		
		/// <summary>
		/// The screen name, handle, or alias that this user identifies
		///	themselves with. screen_names are unique but subject to change.
		///	Use id_str as a user identifier whenever possible. Typically
		///	a maximum of 15 characters long, but some historical accounts
		///	may exist with longer names.
		/// </summary>
		/// <example>
		/// "screen_name":"twitterapi"
		/// </example>
		[JsonProperty("screen_name")]
		public string ScreenName {
			get { return screenName; }
			set { screenName = value; }
		}
		
		[JsonIgnore()]
		bool showAllInlineMedia=false;
		
		/// <summary>
		/// Indicates that the user would like to see media inline. Somewhat disused.
		/// </summary>
		/// <example>
		/// "show_all_inline_media": false
		/// </example>
		[JsonProperty("show_all_inline_media")]
		public bool ShowAllInlineMedia {
			get { return showAllInlineMedia; }
			set { showAllInlineMedia = value; }
		}
		
		[JsonIgnore()]
		TwTweet recentTweet=null;
		
		/*
		 * Пока побудет объектом
		 * 
		 */
		/// <summary>
		/// Nullable. If possible, the user's most recent tweet or retweet. In some
		///	circumstances, this data cannot be provided and this field will be omitted,
		///	null, or empty. Perspectival attributes within tweets embedded within
		///	users cannot always be relied upon.
		/// </summary>
		[JsonProperty("status")]
		public TwTweet RecentTweet {
			get { return recentTweet; }
			set { recentTweet = value; }
		}
		
		[JsonIgnore()]
		int tweetsCount=0;
		
		/// <summary>
		/// The number of tweets (including retweets) issued by the user.
		/// </summary>
		[JsonProperty("statuses_count")]
		public int TweetsCount {
			get { return tweetsCount; }
			set { tweetsCount = value; }
		}
		
		[JsonIgnore()]
		string timeZone=null;
		
		/// <summary>
		/// Nullable. A string describing the Time Zone this user declares themselves within.
		/// </summary>
		/// <example>
		/// "time_zone":"Pacific Time (US & Canada)"
		/// </example>
		[JsonProperty("time_zone")]
		public string TimeZone {
			get { return timeZone; }
			set { timeZone = value; }
		}
		
		[JsonIgnore()]
		string userUrl=null;
		
		/// <summary>
		/// Nullable. A URL provided by the user in association with their profile.
		/// </summary>
		/// <example>
		/// "url":"http:\/\/dev.twitter.com"
		/// </example>
		[JsonProperty("url")]
		public string UserUrl {
			get { return userUrl; }
			set { userUrl = value; }
		}
		
		[JsonIgnore()]
		int? utcOffset;
		
		/// <summary>
		/// Nullable. The offset from GMT/UTC in seconds.
		/// </summary>
		/// <example>
		/// "utc_offset": -18000
		/// </example>
		[JsonProperty("utc_offset")]
		public int? UtcOffset {
			get { return utcOffset; }
			set { utcOffset = value; }
		}
		
		[JsonIgnore()]
		bool verified;
		
		/// <summary>
		/// When true, indicates that the user has a verified account.
		/// </summary>
		[JsonProperty("verified")]
		public bool Verified {
			get { return verified; }
			set { verified = value; }
		}
		
		[JsonIgnore()]
		string withheldInCountries;
		
		/*
		 * 
		 * https://dev.twitter.com/blog/new-withheld-content-fields-api-responses
		 */
		/// <summary>
		/// When present, indicates a textual representation of the two-letter
		///	country codes this user is withheld from.
		/// </summary>
		/// <example>
		/// "withheld_in_countries": "GR, HK, MY"
		/// </example>
		[JsonProperty("withheld_in_countries")]
		public string WithheldInCountries {
			get { return withheldInCountries; }
			set { withheldInCountries = value; }
		}
		
		[JsonIgnore()]
		string withheldScope;
		
		/// <summary>
		/// When present, indicates whether the content being withheld
		///	is the "status" or a "user."
		/// </summary>
		/// <example>
		/// "withheld_scope": "user"
		/// </example>
		[JsonProperty("withheld_scope")]
		public string WithheldScope {
			get { return withheldScope; }
			set { withheldScope = value; }
		}
		
		#endregion
	}
}
